package cn.gov.msa.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;

import cn.gov.msa.dao.DictionaryDetailMapper;
import cn.gov.msa.model.Dictionary;
//import cn.gov.msa.dao.DictionaryDetailMapper;
import cn.gov.msa.model.DictionaryDetail;
import cn.gov.msa.service.DictionaryDetailService;
import cn.gov.msa.util.InfoObjUtil;
import cn.gov.msa.util.ObjectUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class DictionaryDetailServiceImpl implements DictionaryDetailService {


	@Autowired
	private DictionaryDetailMapper dictionaryDetailMapper;
	@Override
	public List<DictionaryDetail> selectDictionary(String dictcode, String pitemcode, String itemname) throws Exception {
		
		DictionaryDetail dictionaryDetail = new DictionaryDetail();
		dictionaryDetail.setDictcode(dictcode);
		if(!"".equals(pitemcode)){
			dictionaryDetail.setPitemcode(pitemcode);
		}
		if(!"".equals(itemname)){
			dictionaryDetail.setItemname(itemname);
		}
		
	    List<DictionaryDetail> listDictionaryDetail = dictionaryDetailMapper.selectDictionary(dictionaryDetail);
	    
	    
		return listDictionaryDetail;
	}

	@Override
	public int deleteDictionaryDetailByDictCode(String dictcode) throws Exception {

		int result = dictionaryDetailMapper.deleteByDictCode(dictcode);
		
		return result;
	}

	@Override
	public DictionaryDetail selectDataByDictCodeAndItemCode(String dictcode, String itemcode) throws Exception {
		DictionaryDetail dictionaryDetail = new DictionaryDetail();
		if(!dictcode.isEmpty()){
			dictionaryDetail.setDictcode(dictcode);
		}
		if(!itemcode.isEmpty()){
			dictionaryDetail.setItemcode(itemcode);
		}
		
        //读取数据库信息
	    List<DictionaryDetail> dictionaryDetailList = dictionaryDetailMapper.selectDictionary(dictionaryDetail);

	    DictionaryDetail dictionaryDetailResult = null;
	    if(dictionaryDetailList.size() > 0){
	    	dictionaryDetailResult = new DictionaryDetail();
	    	dictionaryDetailResult = dictionaryDetailList.get(0);
	    }
	    
	    return dictionaryDetailResult;
	}
}
